import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'

/*以下为新导入*/
import '@/static/styles/theme.css'
import store from './store'
import { routeInterceptor } from './common/interceptor'

Vue.use(routeInterceptor)
store.dispatch('user/initState')
Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
	store,
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}

//新导入
// 添加请求拦截
uni.addInterceptor('request', {
  invoke(args) {
    // 自动添加token
    const token = store.state.user.token
    if (token) {
      args.header = {
        ...args.header,
        Authorization: `Bearer ${token}`
      }
    }
    return args
  },
  fail(err) {
    console.error('请求失败:', err)
  }
})
// #endif